// ContourDistance.h: interface for the CContourDistance class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_CONTOURDISTANCE_H__3CE20C30_2FB2_4237_901D_FF6441588F9C__INCLUDED_)
#define AFX_CONTOURDISTANCE_H__3CE20C30_2FB2_4237_901D_FF6441588F9C__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

struct SPoint;
struct SFPoint;

enum DISTANCE_TYPE
{
	DIST_DEFAULT,
	DIST_NORMAL1,
	DIST_NORMAL2,
};

/** to get normal/distance
 */
class CContourDistance
{
public:
	CContourDistance(const SPoint *lpPoint, int nPoint, DISTANCE_TYPE eType);
	~CContourDistance();

public:
	/// to include special weight for head/tail point or not, default: .F.
	BOOL	m_bIncludeHeadTail;
	/// to use fast index to accelerate or not
	BOOL	m_bUseFastIndex;

public:
	float getDistance(const SPoint *ptCheck, int nCheck, float fAbortMaxValue);
	float getNormal1Distance(const SPoint *ptCheck, int nCheck, float fAbortMaxValue);
	float getNormal2Distance(const SPoint *ptCheck, int nCheck, float fAbortMaxValue);

protected:
	/// source point list, may not near points
	const SPoint	*m_pPoint;
	/// count of points
	int				m_nPoint;
	/// distance type
	DISTANCE_TYPE	m_eType;
	/// last active index
	int				m_nLastIndex;

protected:
	float getMinDist2BackIndex(const SFPoint *ptCheck, const SPoint *lpPoint, int nPoint);
	float getMinDist2FromIndex(const SFPoint *ptCheck, const SPoint *lpPoint, int nPoint);

public:
	static float getDistance(const SFPoint *pt1, const SPoint *pt2);
	static float getDistanceSquare(const SFPoint *pt1, const SPoint *pt2);

protected:
	static float getMinimumDistanceOfPoint2Line(const SFPoint *ptCheck, const SPoint *lpPoint, int nPoint);
	static float getMinimumDistanceSquareOfPoint2Line(const SFPoint *ptCheck, const SPoint *lpPoint, int nPoint, int *pnIndex);
};

#endif // !defined(AFX_CONTOURDISTANCE_H__3CE20C30_2FB2_4237_901D_FF6441588F9C__INCLUDED_)
